﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using log4net;
using System.Configuration;

namespace Cn.Edwon.Web {
    public class WebConfig {
        public static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        /// <summary>
        /// 获取AppSettings的值
        /// </summary>
        /// <param name="rKey"></param>
        /// <returns></returns>
        private static String GetAppSetting(String rKey) {
            return ConfigurationManager.AppSettings[rKey];
        }
        public static String GetAppSetting(String rKey,String rDefault) {
            String val = ConfigurationManager.AppSettings[rKey];
            return (val == null) ? rDefault : val;
        }
        /// <summary>
        /// 获取AppSettings的值
        /// </summary>
        /// <param name="rKey"></param>
        /// <returns></returns>
        public static Int32 GetAppSetting2Int32(String rKey, Int32 rDefault) {
            String val = GetAppSetting(rKey);
            if (val == null) {
                return rDefault;
            } else {
                try {
                    return Convert.ToInt32(val);
                } catch {
                    return rDefault;
                }
            }
        }
        public static Boolean GetAppSetting2Boolean(String rKey,Boolean rDefault) {
            String val = GetAppSetting(rKey);
            if (val == null)
                return rDefault;
            else
                return (val == "1" || val.ToLower() == "true" || val.ToLower() == "yes");
        }
 
    }
}
